﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyMovieSystem
{
    public partial class FrmMyCenter : Form
    {
        public FrmMyCenter()
        {
            InitializeComponent();
        }

        private void FrmMyCenter_Load(object sender, EventArgs e)
        {
            label13.Parent = pictureBox8;
            label3.Text = RoleManage.user.Name;
            label4.Text = RoleManage.user.Score+"";
            txtName.Text = RoleManage.user.Name;
           

        }

        #region 修改btn按钮鼠标悬浮样式
        /// <summary>
        /// 存储控件位置
        /// </summary>
        Point p = new Point();
        /// <summary>
        /// 存储控件大小
        /// </summary>
        Size s = new Size();
        private void button1_MouseEnter(object sender, EventArgs e)
        {
            if (sender.Equals(button2))
                MouseEnters(button2);
            else if (sender.Equals(button3))
                MouseEnters(button3);
            else if (sender.Equals(button4))
                MouseEnters(button4); 
            else if (sender.Equals(button5))
                MouseEnters(button5);
            else if (sender.Equals(button6))
                MouseEnters(button6);
            else if (sender.Equals(button7))
                MouseEnters(button7);
        }
        private void button1_MouseLeave(object sender, EventArgs e)
        {
            if (sender.Equals(button2))
                MouseLeaves(button2);
            else if (sender.Equals(button3))
                MouseLeaves(button3);
            else if (sender.Equals(button4))
                MouseLeaves(button4);
            else if (sender.Equals(button5))
                MouseLeaves(button5);
            else if (sender.Equals(button6))
                MouseLeaves(button6);
            else if (sender.Equals(button7))
                MouseLeaves(button7);
        }
        /// <summary>
        /// 鼠标停留控件样式
        /// </summary>
        /// <param name="btn"></param>
        private void MouseEnters(Button btn)
        {
            p = btn.Location;
            s = btn.Size;
            btn.Location = new Point(p.X - 4, p.Y - 5);
        }
        /// <summary>
        /// 鼠标离开控件后样式
        /// </summary>
        /// <param name="btn"></param>
        private void MouseLeaves(Button btn)
        {
            btn.Location = p;
        }
        #endregion

        #region 左侧按钮点击事件
        //看过电影
        private void button4_Click(object sender, EventArgs e)
        {
            dataGridView1.Visible = true;
            panel3.Visible = false;
            label5.Visible = false;
            dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = new BindingList<Movie>(RoleManage.user.LookOffMovie);
        }
        //优惠券
        private void button2_Click(object sender, EventArgs e)
        {
            label5.Visible = true;
            dataGridView1.Visible = false;
            panel3.Visible = false;
        }
        //想看电影
        private void button3_Click(object sender, EventArgs e)
        {
            dataGridView1.Visible = true;
            label5.Visible = false;
            panel3.Visible = false;
            dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = new BindingList<Movie>(RoleManage.user.WantMovie);
        }

        //退出登录
        private void button7_Click(object sender, EventArgs e)
        {
            DialogResult r = MessageBox.Show("确定退出当前账户吗?","提示：",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
            if (r != DialogResult.OK)
                return;
            FrmLogin login = new FrmLogin();
            RoleManage.user = null;
            login.Show();
            FrmClos.bridegeOfForm1.Hide();
            this.Close();
        }

        //修改资料
        private void button8_Click(object sender, EventArgs e)
        {
            if (txtPwd.Text.Trim().Length < 1 || txtnewPwd.Text.Trim().Length < 1)
            {
                MessageBox.Show("信息不能为空!","提示：");
                return;
            }
            RoleManage.dirRole[RoleManage.user.Name].Pwd = txtnewPwd.Text.Trim();
            MessageBox.Show("修改成功，账号需重新登录！","提示：");
            RoleManage.SerializeRole();
            FrmLogin login = new FrmLogin();
            login.Show();
            FrmClos.bridegeOfForm1.Hide();
            this.Close();
            
        }

        private void button5_Click_1(object sender, EventArgs e)
        {
            panel3.Visible = true;
            label5.Visible = false;
            dataGridView1.Visible = false;
        }

        #endregion
    }
}
